home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / fstrash / RCS / fsSetFD.c,v < prev    next >
Encoding:
Text File  |  1990-07-10  |  31.7 KB  |  1,220 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    jhh:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.07.09.21.45.45;  author jhh;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * fsSetFd.c --
  27.  *
  28.  *    These are the routines that fill in the file descriptors of the files
  29.  *    in the file system.
  30.  *
  31.  * Copyright 1989 Regents of the University of California
  32.  * Permission to use, copy, modify, and distribute this
  33.  * software and its documentation for any purpose and without
  34.  * fee is hereby granted, provided that the above copyright
  35.  * notice appear in all copies.  The University of California
  36.  * makes no representations about the suitability of this
  37.  * software for any purpose.  It is provided "as is" without
  38.  * express or implied warranty.
  39.  */
  40.  
  41. #ifndef lint
  42. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.2 89/01/07 04:12:18 rab Exp $ SPRITE (Berkeley)";
  43. #endif /* not lint */
  44.  
  45. #include "sprite.h"
  46. #include "option.h"
  47. #include "diskUtils.h"
  48. #include <stdio.h>
  49. #include <sys/file.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52.  
  53. extern Boolean rootFree;
  54. extern Boolean rootFile;
  55. extern Boolean noRoot;
  56.  
  57.  
  58. /*
  59.  *----------------------------------------------------------------------
  60.  *
  61.  * SetRootFileDescriptor --
  62.  *
  63.  *    File 2.
  64.  *    Set up the file descriptor for the root directory. The root
  65.  *    directory uses block 0.
  66.  *
  67.  * Results:
  68.  *    Fill in the file descriptor.
  69.  *
  70.  * Side effects:
  71.  *    None.
  72.  *
  73.  *----------------------------------------------------------------------
  74.  */
  75. void
  76. SetRootFileDescriptor(fileDescPtr)
  77.     register FsFileDescriptor *fileDescPtr;
  78. {
  79.     Time time;
  80.     int index;
  81.  
  82.     if (noRoot) {
  83.     bzero((Address) fileDescPtr, sizeof(FsFileDescriptor));
  84.     return;
  85.     }
  86.     fileDescPtr->flags = rootFree ? FS_FD_FREE :  FS_FD_ALLOC;
  87.     fileDescPtr->fileType = rootFile ? FS_FILE : FS_DIRECTORY;
  88.     fileDescPtr->permissions = 0755;
  89.     fileDescPtr->uid = 0;
  90.     fileDescPtr->gid = 0;
  91.     fileDescPtr->lastByte = FS_BLOCK_SIZE-1;
  92.     fileDescPtr->firstByte = -1;
  93.     fileDescPtr->numLinks = 3;
  94.     /*
  95.      * Can't know device information because that depends on
  96.      * the way the system is configured.
  97.      */
  98.     fileDescPtr->devServerID = -1;
  99.     fileDescPtr->devType = -1;
  100.     fileDescPtr->devUnit = -1;
  101.  
  102.     /*
  103.      * Set the time stamps.  This assumes that universal time, not local
  104.      * time, is used for time stamps.
  105.      */
  106.     Sys_GetTimeOfDay(&time, NULL, NULL);
  107.     fileDescPtr->createTime = time.seconds;
  108.     fileDescPtr->accessTime = 0;
  109.     fileDescPtr->descModifyTime = time.seconds;
  110.     fileDescPtr->dataModifyTime = time.seconds;
  111.  
  112.     /*
  113.      * Place the data in the first filesystem block.
  114.      */
  115.     fileDescPtr->direct[0] = 0;
  116.     for (index = 1; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  117.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  118.     }
  119.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  120.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  121.     }
  122.     fileDescPtr->numKbytes = 4;
  123.     fileDescPtr->version = 1;
  124. }
  125.  
  126. /*
  127.  *----------------------------------------------------------------------
  128.  *
  129.  * SetBadBlockFileDescriptor --
  130.  *
  131.  *    File 1.
  132.  *    Set up the file descriptor for the bad block file.
  133.  *
  134.  * Results:
  135.  *    Fill in the file descriptor.
  136.  *
  137.  * Side effects:
  138.  *    None.
  139.  *
  140.  *----------------------------------------------------------------------
  141.  */
  142. void
  143. SetBadBlockFileDescriptor(fileDescPtr)
  144.     register FsFileDescriptor *fileDescPtr;
  145. {
  146.     Time time;
  147.     int index;
  148.  
  149.     fileDescPtr->flags = FS_FD_ALLOC;
  150.     fileDescPtr->fileType = FS_FILE;
  151.     fileDescPtr->permissions = 0000;
  152.     fileDescPtr->uid = 0;
  153.     fileDescPtr->gid = 0;
  154.     fileDescPtr->lastByte = -1;
  155.     fileDescPtr->firstByte = -1;
  156.     fileDescPtr->numLinks = 0;        /* Intentionally unreferenced */
  157.     /*
  158.      * Can't know device information because that depends on
  159.      * the way the system is configured.
  160.      */
  161.     fileDescPtr->devServerID = -1;
  162.     fileDescPtr->devType = -1;
  163.     fileDescPtr->devUnit = -1;
  164.  
  165.     /*
  166.      * Set the time stamps.  This assumes that universal time, not local
  167.      * time, is used for time stamps.
  168.      */
  169.     Sys_GetTimeOfDay(&time, NULL, NULL);
  170.     fileDescPtr->createTime = time.seconds;
  171.     fileDescPtr->accessTime = 0;
  172.     fileDescPtr->descModifyTime = time.seconds;
  173.     fileDescPtr->dataModifyTime = time.seconds;
  174.  
  175.     /*
  176.      * Place the data in the first filesystem block.
  177.      */
  178.     for (index = 0; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  179.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  180.     }
  181.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  182.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  183.     }
  184.     fileDescPtr->numKbytes = 0;
  185.     fileDescPtr->version = 1;
  186. }
  187.  
  188. /*
  189.  *----------------------------------------------------------------------
  190.  *
  191.  * SetLostFoundFileDescriptor --
  192.  *
  193.  *    File 3.
  194.  *    Set up the file descriptor for the lost and found directory.
  195.  *
  196.  * Results:
  197.  *    Fill in the file descriptor.
  198.  *
  199.  * Side effects:
  200.  *    None.
  201.  *
  202.  *----------------------------------------------------------------------
  203.  */
  204. void
  205. SetLostFoundFileDescriptor(fileDescPtr)
  206.     register FsFileDescriptor *fileDescPtr;
  207. {
  208.     Time time;
  209.     int index;
  210.  
  211.     fileDescPtr->flags = FS_FD_ALLOC;
  212.     fileDescPtr->fileType = FS_DIRECTORY;
  213.     fileDescPtr->permissions = 0755;
  214.     fileDescPtr->uid = 0;
  215.     fileDescPtr->gid = 0;
  216.     fileDescPtr->lastByte = FS_NUM_LOST_FOUND_BLOCKS * FS_BLOCK_SIZE - 1;
  217.     fileDescPtr->firstByte = -1;
  218.     fileDescPtr->numLinks = 2;
  219.     /*
  220.      * Can't know device information because that depends on
  221.      * the way the system is configured.
  222.      */
  223.     fileDescPtr->devServerID = -1;
  224.     fileDescPtr->devType = -1;
  225.     fileDescPtr->devUnit = -1;
  226.  
  227.     /*
  228.      * Set the time stamps.  This assumes that universal time, not local
  229.      * time, is used for time stamps.
  230.      */
  231.     Sys_GetTimeOfDay(&time, NULL, NULL);
  232.     fileDescPtr->createTime = time.seconds;
  233.     fileDescPtr->accessTime = 0;
  234.     fileDescPtr->descModifyTime = time.seconds;
  235.     fileDescPtr->dataModifyTime = time.seconds;
  236.  
  237.     for (index = 0; index < FS_NUM_LOST_FOUND_BLOCKS ; index++) {
  238.     fileDescPtr->direct[index] = FS_FRAGMENTS_PER_BLOCK * (index + 1);
  239.     }
  240.     for (; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  241.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  242.     }
  243.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  244.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  245.     }
  246.     fileDescPtr->numKbytes = 8;
  247.     fileDescPtr->version = 1;
  248. }
  249.  
  250. /*
  251.  *----------------------------------------------------------------------
  252.  *
  253.  * SetEmptyFileDescriptor --
  254.  *
  255.  *    File 4
  256.  *    Set up a file descriptor for an empty file.
  257.  *
  258.  * Results:
  259.  *    Fill in the file descriptor.
  260.  *
  261.  * Side effects:
  262.  *    None.
  263.  *
  264.  *----------------------------------------------------------------------
  265.  */
  266. void
  267. SetEmptyFileDescriptor(fileDescPtr)
  268.     register FsFileDescriptor *fileDescPtr;
  269. {
  270.     Time time;
  271.     int index;
  272.  
  273.     fileDescPtr->flags = FS_FD_ALLOC;
  274.     fileDescPtr->fileType = FS_FILE;
  275.     fileDescPtr->permissions = 0666;
  276.     fileDescPtr->uid = 0;
  277.     fileDescPtr->gid = 0;
  278.     fileDescPtr->lastByte = -1;
  279.     fileDescPtr->firstByte = -1;
  280.     fileDescPtr->numLinks = 1;
  281.     /*
  282.      * Can't know device information because that depends on
  283.      * the way the system is configured.
  284.      */
  285.     fileDescPtr->devServerID = -1;
  286.     fileDescPtr->devType = -1;
  287.     fileDescPtr->devUnit = -1;
  288.  
  289.     /*
  290.      * Set the time stamps.  This assumes that universal time, not local
  291.      * time, is used for time stamps.
  292.      */
  293.     Sys_GetTimeOfDay(&time, NULL, NULL);
  294.     fileDescPtr->createTime = time.seconds;
  295.     fileDescPtr->accessTime = 0;
  296.     fileDescPtr->descModifyTime = time.seconds;
  297.     fileDescPtr->dataModifyTime = time.seconds;
  298.  
  299.     for (index = 0; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  300.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  301.     }
  302.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  303.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  304.     }
  305.     fileDescPtr->numKbytes = 0;
  306.     fileDescPtr->version = 1;
  307. }
  308. /*
  309.  *----------------------------------------------------------------------
  310.  *
  311.  * SetTooBigFD --
  312.  *
  313.  *    File 6
  314.  *    The file size is bigger than the number of blocks.
  315.  *    The block count is too large.
  316.  *
  317.  * Results:
  318.  *    Fill in the file descriptor.
  319.  *
  320.  * Side effects:
  321.  *    None.
  322.  *
  323.  *----------------------------------------------------------------------
  324.  */
  325. void
  326. SetTooBigFD(fileDescPtr)
  327.     register FsFileDescriptor *fileDescPtr;
  328. {
  329.     Time time;
  330.     int index;
  331.     int numBlocks = 1;
  332.     int start;
  333.  
  334.  
  335.     fileDescPtr->flags = FS_FD_ALLOC;
  336.     fileDescPtr->fileType = FS_FILE;
  337.     fileDescPtr->permissions = 0755;
  338.     fileDescPtr->uid = 0;
  339.     fileDescPtr->gid = 0;
  340.     fileDescPtr->lastByte = numBlocks * FS_BLOCK_SIZE + 10;
  341.     fileDescPtr->firstByte = -1;
  342.     fileDescPtr->numLinks = 2;
  343.     /*
  344.      * Can't know device information because that depends on
  345.      * the way the system is configured.
  346.      */
  347.     fileDescPtr->devServerID = -1;
  348.     fileDescPtr->devType = -1;
  349.     fileDescPtr->devUnit = -1;
  350.  
  351.     /*
  352.      * Set the time stamps.  This assumes that universal time, not local
  353.      * time, is used for time stamps.
  354.      */
  355.     Sys_GetTimeOfDay(&time, NULL, NULL);
  356.     fileDescPtr->createTime = time.seconds;
  357.     fileDescPtr->accessTime = 0;
  358.     fileDescPtr->descModifyTime = time.seconds;
  359.     fileDescPtr->dataModifyTime = time.seconds;
  360.  
  361.     start = (FS_NUM_LOST_FOUND_BLOCKS + 1);
  362.  
  363.     for (index = 0; index < numBlocks ; index++) {
  364.     fileDescPtr->direct[index] = (start + index) * FS_FRAGMENTS_PER_BLOCK;
  365.     }
  366.     for (; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  367.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  368.     }
  369.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  370.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  371.     }
  372.     fileDescPtr->numKbytes = 8;
  373.     fileDescPtr->version = 1;
  374. }
  375.  
  376. /*
  377.  *----------------------------------------------------------------------
  378.  *
  379.  * SetTooSmallFD --
  380.  *
  381.  *     File 7
  382.  *    The file size is smaller than the number of blocks.
  383.  *
  384.  * Results:
  385.  *    None.
  386.  *
  387.  * Side effects:
  388.  *    None.
  389.  *
  390.  *----------------------------------------------------------------------
  391.  */
  392. void
  393. SetTooSmallFD(fileDescPtr)
  394.     register FsFileDescriptor *fileDescPtr;
  395. {
  396.     Time time;
  397.     int index;
  398.     int num1KBlocks = 2;
  399.     int start;
  400.  
  401.  
  402.     fileDescPtr->flags = FS_FD_ALLOC;
  403.     fileDescPtr->fileType = FS_FILE;
  404.     fileDescPtr->permissions = 0755;
  405.     fileDescPtr->uid = 0;
  406.     fileDescPtr->gid = 0;
  407.     fileDescPtr->lastByte = (num1KBlocks - 1) * 
  408.                 (FS_BLOCK_SIZE / FS_FRAGMENTS_PER_BLOCK) - 10;
  409.     fileDescPtr->firstByte = -1;
  410.     fileDescPtr->numLinks = 1;
  411.     /*
  412.      * Can't know device information because that depends on
  413.      * the way the system is configured.
  414.      */
  415.     fileDescPtr->devServerID = -1;
  416.     fileDescPtr->devType = -1;
  417.     fileDescPtr->devUnit = -1;
  418.  
  419.     /*
  420.      * Set the time stamps.  This assumes that universal time, not local
  421.      * time, is used for time stamps.
  422.      */
  423.     Sys_GetTimeOfDay(&time, NULL, NULL);
  424.     fileDescPtr->createTime = time.seconds;
  425.     fileDescPtr->accessTime = 0;
  426.     fileDescPtr->descModifyTime = time.seconds;
  427.     fileDescPtr->dataModifyTime = time.seconds;
  428.  
  429.     start = 16;
  430.  
  431.     for (index = 0; index < num1KBlocks ; index++) {
  432.     fileDescPtr->direct[index] = (start + index);
  433.     }
  434.     for (; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  435.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  436.     }
  437.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  438.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  439.     }
  440.     fileDescPtr->numKbytes = 2;
  441.     fileDescPtr->version = 1;
  442. }
  443.  
  444. /*
  445.  *----------------------------------------------------------------------
  446.  *
  447.  * SetHoleFileFD --
  448.  *
  449.  *    File 8
  450.  *    Nothing wrong here - just a file with a hole.
  451.  *
  452.  * Results:
  453.  *    None.
  454.  *
  455.  * Side effects:
  456.  *    None.
  457.  *
  458.  *----------------------------------------------------------------------
  459.  */
  460. void
  461. SetHoleFileFD(headerPtr, partFID, fileDescPtr)
  462.     register FsFileDescriptor *fileDescPtr;
  463.     FsDomainHeader *headerPtr;
  464.     int partFID;
  465. {
  466.     Time time;
  467.     int index;
  468.     char block[FS_BLOCK_SIZE];
  469.     int *indBlock = (int *) block;
  470.     int status;
  471.     int blockNum;
  472.  
  473.  
  474.     fileDescPtr->flags = FS_FD_ALLOC;
  475.     fileDescPtr->fileType = FS_FILE;
  476.     fileDescPtr->permissions = 0755;
  477.     fileDescPtr->uid = 0;
  478.     fileDescPtr->gid = 0;
  479.     fileDescPtr->lastByte = FS_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  480.                 FS_INDICES_PER_BLOCK * FS_BLOCK_SIZE +
  481.                 1;
  482.     fileDescPtr->firstByte = -1;
  483.     fileDescPtr->numLinks = 1;
  484.     /*
  485.      * Can't know device information because that depends on
  486.      * the way the system is configured.
  487.      */
  488.     fileDescPtr->devServerID = -1;
  489.     fileDescPtr->devType = -1;
  490.     fileDescPtr->devUnit = -1;
  491.  
  492.     /*
  493.      * Set the time stamps.  This assumes that universal time, not local
  494.      * time, is used for time stamps.
  495.      */
  496.     Sys_GetTimeOfDay(&time, NULL, NULL);
  497.     fileDescPtr->createTime = time.seconds;
  498.     fileDescPtr->accessTime = 0;
  499.     fileDescPtr->descModifyTime = time.seconds;
  500.     fileDescPtr->dataModifyTime = time.seconds;
  501.  
  502.  
  503.     for (index = 0; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  504.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  505.     }
  506.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  507.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  508.     blockNum = 20 + FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset ;
  509.     fileDescPtr->indirect[1] = blockNum;
  510.     indBlock[0] = blockNum + 4;
  511.     for (index = 1; index < FS_INDICES_PER_BLOCK;index++) {
  512.     indBlock[index] = FS_NIL_INDEX;
  513.     }
  514.     status = Disk_BlockWrite(partFID, headerPtr, headerPtr->dataOffset + 5,
  515.                  1, block);
  516.     if (status != SUCCESS) {
  517.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  518.     return;
  519.     }
  520.     blockNum += 4;
  521.     indBlock[0] = blockNum + 4 - FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  522.     for (index = 1; index < FS_INDICES_PER_BLOCK;index++) {
  523.     indBlock[index] = FS_NIL_INDEX;
  524.     }
  525.     status = Disk_BlockWrite(partFID, headerPtr, headerPtr->dataOffset + 6, 
  526.                  1, block);
  527.     if (status != SUCCESS) {
  528.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  529.     return;
  530.     }
  531.     fileDescPtr->numKbytes = 4;
  532.     fileDescPtr->version = 1;
  533. }
  534.  
  535. /*
  536.  *----------------------------------------------------------------------
  537.  *
  538.  * SetHoleDirFD --
  539.  *
  540.  *    File 9
  541.  *    Directory with a hole, which isn't allowed.
  542.  *
  543.  * Results:
  544.  *    None.
  545.  *
  546.  * Side effects:
  547.  *    None.
  548.  *
  549.  *----------------------------------------------------------------------
  550.  */
  551. void
  552. SetHoleDirFD(headerPtr, partFID, fileDescPtr)
  553.     register FsFileDescriptor *fileDescPtr;
  554.     FsDomainHeader *headerPtr;
  555.     int partFID;
  556. {
  557.     Time time;
  558.     int index;
  559.     char block[FS_BLOCK_SIZE];
  560.     int *indBlock = (int *) block;
  561.     int status;
  562.     int blockNum;
  563.  
  564.  
  565.     fileDescPtr->flags = FS_FD_ALLOC;
  566.     fileDescPtr->fileType = FS_DIRECTORY;
  567.     fileDescPtr->permissions = 0755;
  568.     fileDescPtr->uid = 0;
  569.     fileDescPtr->gid = 0;
  570.     fileDescPtr->lastByte = 2 * FS_BLOCK_SIZE -1;
  571.     fileDescPtr->firstByte = -1;
  572.     fileDescPtr->numLinks = 1;
  573.     /*
  574.      * Can't know device information because that depends on
  575.      * the way the system is configured.
  576.      */
  577.     fileDescPtr->devServerID = -1;
  578.     fileDescPtr->devType = -1;
  579.     fileDescPtr->devUnit = -1;
  580.  
  581.     /*
  582.      * Set the time stamps.  This assumes that universal time, not local
  583.      * time, is used for time stamps.
  584.      */
  585.     Sys_GetTimeOfDay(&time, NULL, NULL);
  586.     fileDescPtr->createTime = time.seconds;
  587.     fileDescPtr->accessTime = 0;
  588.     fileDescPtr->descModifyTime = time.seconds;
  589.     fileDescPtr->dataModifyTime = time.seconds;
  590.  
  591.  
  592.     fileDescPtr->direct[0] = 32;
  593.     fileDescPtr->direct[1] = FS_NIL_INDEX;
  594.     fileDescPtr->direct[2] = 36;
  595.     for (index = 3; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  596.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  597.     }
  598.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  599.     fileDescPtr->indirect[1] = FS_NIL_INDEX;
  600.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  601.     fileDescPtr->numKbytes = 1;
  602.     fileDescPtr->version = 1;
  603. }
  604.  
  605. /*
  606.  *----------------------------------------------------------------------
  607.  *
  608.  * SetBadEntryFileFD --
  609.  *
  610.  *    File 10.
  611.  *    The first indirect block contains an illegal index.
  612.  *    First direct block number is bad.
  613.  *
  614.  * Results:
  615.  *    None.
  616.  *
  617.  * Side effects:
  618.  *    None.
  619.  *
  620.  *----------------------------------------------------------------------
  621.  */
  622. void
  623. SetBadEntryFileFD(headerPtr, partFID, fileDescPtr)
  624.     register FsFileDescriptor *fileDescPtr;
  625.     FsDomainHeader *headerPtr;
  626.     int partFID;
  627. {
  628.     Time time;
  629.     int index;
  630.     char block[FS_BLOCK_SIZE];
  631.     int *indBlock = (int *) block;
  632.     int status;
  633.     int blockNum;
  634.  
  635.  
  636.     fileDescPtr->flags = FS_FD_ALLOC;
  637.     fileDescPtr->fileType = FS_FILE;
  638.     fileDescPtr->permissions = 0755;
  639.     fileDescPtr->uid = 0;
  640.     fileDescPtr->gid = 0;
  641.     fileDescPtr->lastByte = FS_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  642.                 FS_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1;
  643.     fileDescPtr->firstByte = -1;
  644.     fileDescPtr->numLinks = 1;
  645.     /*
  646.      * Can't know device information because that depends on
  647.      * the way the system is configured.
  648.      */
  649.     fileDescPtr->devServerID = -1;
  650.     fileDescPtr->devType = -1;
  651.     fileDescPtr->devUnit = -1;
  652.  
  653.     /*
  654.      * Set the time stamps.  This assumes that universal time, not local
  655.      * time, is used for time stamps.
  656.      */
  657.     Sys_GetTimeOfDay(&time, NULL, NULL);
  658.     fileDescPtr->createTime = time.seconds;
  659.     fileDescPtr->accessTime = 0;
  660.     fileDescPtr->descModifyTime = time.seconds;
  661.     fileDescPtr->dataModifyTime = time.seconds;
  662.  
  663.     fileDescPtr->direct[0] = 10000000;
  664.     for (index = 1; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  665.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  666.     }
  667.     blockNum = 44 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  668.     fileDescPtr->indirect[0] = blockNum;
  669.     bzero(block,FS_BLOCK_SIZE);
  670.  
  671.     indBlock[0] = 10000000;
  672.     for (index = 1; index < FS_INDICES_PER_BLOCK;index++) {
  673.     indBlock[index] = FS_NIL_INDEX;
  674.     }
  675.     status = Disk_BlockWrite(partFID, headerPtr,headerPtr->dataOffset + 11,  
  676.                  1, block);
  677.     if (status != SUCCESS) {
  678.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  679.     return;
  680.     }
  681.     blockNum = 48 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  682.     fileDescPtr->indirect[1] = blockNum;
  683.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  684.     indBlock[0] = blockNum + 4;
  685.     for (index = 1; index < FS_INDICES_PER_BLOCK;index++) {
  686.     indBlock[index] = FS_NIL_INDEX;
  687.     }
  688.     status = Disk_BlockWrite(partFID, headerPtr,headerPtr->dataOffset + 12,
  689.                  1, block);
  690.     if (status != SUCCESS) {
  691.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  692.     return;
  693.     }
  694.     indBlock[0] = 56;
  695.     for (index = 1; index < FS_INDICES_PER_BLOCK;index++) {
  696.     indBlock[index] = FS_NIL_INDEX;
  697.     }
  698.     status = Disk_BlockWrite(partFID, headerPtr,headerPtr->dataOffset + 13 ,
  699.                  1, block);
  700.     if (status != SUCCESS) {
  701.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  702.     return;
  703.     }
  704.     fileDescPtr->numKbytes = 1;
  705.     fileDescPtr->version = 1;
  706. }
  707.  
  708. /*
  709.  *----------------------------------------------------------------------
  710.  *
  711.  * SetFragFileFD --
  712.  *
  713.  *    File 11
  714.  *    The first block is a fragment in the middle of a file.
  715.  *
  716.  * Results:
  717.  *    None.
  718.  *
  719.  * Side effects:
  720.  *    None.
  721.  *
  722.  *----------------------------------------------------------------------
  723.  */
  724. void
  725. SetFragFileFD(fileDescPtr)
  726.     register FsFileDescriptor *fileDescPtr;
  727. {
  728.     Time time;
  729.     int index;
  730.  
  731.  
  732.     fileDescPtr->flags = FS_FD_ALLOC;
  733.     fileDescPtr->fileType = FS_FILE;
  734.     fileDescPtr->permissions = 0755;
  735.     fileDescPtr->uid = 0;
  736.     fileDescPtr->gid = 0;
  737.     fileDescPtr->lastByte = FS_BLOCK_SIZE + FS_FRAGMENT_SIZE -1;
  738.     fileDescPtr->firstByte = -1;
  739.     fileDescPtr->numLinks = 1;
  740.     /*
  741.      * Can't know device information because that depends on
  742.      * the way the system is configured.
  743.      */
  744.     fileDescPtr->devServerID = -1;
  745.     fileDescPtr->devType = -1;
  746.     fileDescPtr->devUnit = -1;
  747.  
  748.     /*
  749.      * Set the time stamps.  This assumes that universal time, not local
  750.      * time, is used for time stamps.
  751.      */
  752.     Sys_GetTimeOfDay(&time, NULL, NULL);
  753.     fileDescPtr->createTime = time.seconds;
  754.     fileDescPtr->accessTime = 0;
  755.     fileDescPtr->descModifyTime = time.seconds;
  756.     fileDescPtr->dataModifyTime = time.seconds;
  757.  
  758.     fileDescPtr->direct[0] = 61;
  759.     fileDescPtr->direct[1] = 62;
  760.     for (index = 2; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  761.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  762.     }
  763.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  764.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  765.     }
  766.     fileDescPtr->numKbytes = 2;
  767.     fileDescPtr->version = 1;
  768. }
  769.  
  770. /*
  771.  *----------------------------------------------------------------------
  772.  *
  773.  * SetCopyFragFileFD --
  774.  *
  775.  *    File 12
  776.  *    The first direct block shares block 60  with file 11. 
  777.  *    The second direct block shares fragment 62  with file 11. 
  778.  *
  779.  * Results:
  780.  *    None.
  781.  *
  782.  * Side effects:
  783.  *    None.
  784.  *
  785.  *----------------------------------------------------------------------
  786.  */
  787. void
  788. SetCopyFragFileFD(fileDescPtr)
  789.     register FsFileDescriptor *fileDescPtr;
  790. {
  791.     Time time;
  792.     int index;
  793.  
  794.  
  795.     fileDescPtr->flags = FS_FD_ALLOC;
  796.     fileDescPtr->fileType = FS_FILE;
  797.     fileDescPtr->permissions = 0755;
  798.     fileDescPtr->uid = 0;
  799.     fileDescPtr->gid = 0;
  800.     fileDescPtr->lastByte = FS_BLOCK_SIZE + FS_FRAGMENT_SIZE -1;
  801.     fileDescPtr->firstByte = -1;
  802.     fileDescPtr->numLinks = 1;
  803.     /*
  804.      * Can't know device information because that depends on
  805.      * the way the system is configured.
  806.      */
  807.     fileDescPtr->devServerID = -1;
  808.     fileDescPtr->devType = -1;
  809.     fileDescPtr->devUnit = -1;
  810.  
  811.     /*
  812.      * Set the time stamps.  This assumes that universal time, not local
  813.      * time, is used for time stamps.
  814.      */
  815.     Sys_GetTimeOfDay(&time, NULL, NULL);
  816.     fileDescPtr->createTime = time.seconds;
  817.     fileDescPtr->accessTime = 0;
  818.     fileDescPtr->descModifyTime = time.seconds;
  819.     fileDescPtr->dataModifyTime = time.seconds;
  820.  
  821.     fileDescPtr->direct[0] = 60;
  822.     fileDescPtr->direct[1] = 62;
  823.     for (index = 2; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  824.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  825.     }
  826.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  827.     fileDescPtr->indirect[1] = FS_NIL_INDEX;
  828.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  829.     fileDescPtr->numKbytes = 4;
  830.     fileDescPtr->version = 1;
  831. }
  832.  
  833. /*
  834.  *----------------------------------------------------------------------
  835.  *
  836.  * SetCopyBlockFileFD --
  837.  *
  838.  *     File 13
  839.  *    Shares a block with file 10.
  840.  *    First indirect block number is bad.
  841.  *
  842.  * Results:
  843.  *    None.
  844.  *
  845.  * Side effects:
  846.  *    None.
  847.  *
  848.  *----------------------------------------------------------------------
  849.  */
  850. void
  851. SetCopyBlockFileFD(fileDescPtr)
  852.     register FsFileDescriptor *fileDescPtr;
  853. {
  854.     Time time;
  855.     int index;
  856.  
  857.     fileDescPtr->flags = FS_FD_ALLOC;
  858.     fileDescPtr->fileType = FS_FILE;
  859.     fileDescPtr->permissions = 0755;
  860.     fileDescPtr->uid = 0;
  861.     fileDescPtr->gid = 0;
  862.     fileDescPtr->lastByte =FS_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  863.                 FS_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1 ;
  864.     fileDescPtr->firstByte = -1;
  865.     fileDescPtr->numLinks = 1;
  866.     /*
  867.      * Can't know device information because that depends on
  868.      * the way the system is configured.
  869.      */
  870.     fileDescPtr->devServerID = -1;
  871.     fileDescPtr->devType = -1;
  872.     fileDescPtr->devUnit = -1;
  873.  
  874.     /*
  875.      * Set the time stamps.  This assumes that universal time, not local
  876.      * time, is used for time stamps.
  877.      */
  878.     Sys_GetTimeOfDay(&time, NULL, NULL);
  879.     fileDescPtr->createTime = time.seconds;
  880.     fileDescPtr->accessTime = 0;
  881.     fileDescPtr->descModifyTime = time.seconds;
  882.     fileDescPtr->dataModifyTime = time.seconds;
  883.  
  884.     fileDescPtr->direct[0] = 56;
  885.     fileDescPtr->direct[1] = 0;
  886.     for (index = 2; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  887.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  888.     }
  889.     fileDescPtr->indirect[0] = 8;
  890.     fileDescPtr->indirect[1] = FS_NIL_INDEX;
  891.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  892.     fileDescPtr->numKbytes = 8;
  893.     fileDescPtr->version = 1;
  894. }
  895.  
  896. /*
  897.  *----------------------------------------------------------------------
  898.  *
  899.  * SetCopyIndBlockFileFD --
  900.  *
  901.  *     File 14
  902.  *    Shares an indirect block with file 10
  903.  *
  904.  * Results:
  905.  *    None.
  906.  *
  907.  * Side effects:
  908.  *    None.
  909.  *
  910.  *----------------------------------------------------------------------
  911.  */
  912. void
  913. SetCopyIndBlockFileFD(headerPtr, partFID, fileDescPtr)
  914.     register FsFileDescriptor *fileDescPtr;
  915.     FsDomainHeader *headerPtr;
  916.     int partFID;
  917. {
  918.     Time time;
  919.     int index;
  920.     int blockNum;
  921.  
  922.  
  923.     fileDescPtr->flags = FS_FD_ALLOC;
  924.     fileDescPtr->fileType = FS_FILE;
  925.     fileDescPtr->permissions = 0755;
  926.     fileDescPtr->uid = 0;
  927.     fileDescPtr->gid = 0;
  928.     fileDescPtr->lastByte = FS_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  929.                 FS_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1;
  930.     fileDescPtr->firstByte = -1;
  931.     fileDescPtr->numLinks = 1;
  932.     /*
  933.      * Can't know device information because that depends on
  934.      * the way the system is configured.
  935.      */
  936.     fileDescPtr->devServerID = -1;
  937.     fileDescPtr->devType = -1;
  938.     fileDescPtr->devUnit = -1;
  939.  
  940.     /*
  941.      * Set the time stamps.  This assumes that universal time, not local
  942.      * time, is used for time stamps.
  943.      */
  944.     Sys_GetTimeOfDay(&time, NULL, NULL);
  945.     fileDescPtr->createTime = time.seconds;
  946.     fileDescPtr->accessTime = 0;
  947.     fileDescPtr->descModifyTime = time.seconds;
  948.     fileDescPtr->dataModifyTime = time.seconds;
  949.  
  950.  
  951.     for (index = 0; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  952.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  953.     }
  954.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  955.     blockNum = 48 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  956.     fileDescPtr->indirect[1] = blockNum;
  957.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  958.     fileDescPtr->numKbytes = 4;
  959.     fileDescPtr->version = 1;
  960. }
  961.  
  962. /*
  963.  *----------------------------------------------------------------------
  964.  *
  965.  * SetCopyBogusIndBlockFileFD --
  966.  *
  967.  *     File 15
  968.  *    Shares an indirect block with file 10, but the block contains bogus
  969.  *        indices.
  970.  *
  971.  * Results:
  972.  *    None.
  973.  *
  974.  * Side effects:
  975.  *    None.
  976.  *
  977.  *----------------------------------------------------------------------
  978.  */
  979. void
  980. SetCopyBogusIndBlockFileFD(headerPtr, partFID, fileDescPtr)
  981.     register FsFileDescriptor *fileDescPtr;
  982.     FsDomainHeader *headerPtr;
  983.     int partFID;
  984. {
  985.     Time time;
  986.     int index;
  987.     int blockNum;
  988.  
  989.  
  990.     fileDescPtr->flags = FS_FD_ALLOC;
  991.     fileDescPtr->fileType = FS_FILE;
  992.     fileDescPtr->permissions = 0755;
  993.     fileDescPtr->uid = 0;
  994.     fileDescPtr->gid = 0;
  995.     fileDescPtr->lastByte = FS_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  996.                 FS_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1;
  997.     fileDescPtr->firstByte = -1;
  998.     fileDescPtr->numLinks = 1;
  999.     /*
  1000.      * Can't know device information because that depends on
  1001.      * the way the system is configured.
  1002.      */
  1003.     fileDescPtr->devServerID = -1;
  1004.     fileDescPtr->devType = -1;
  1005.     fileDescPtr->devUnit = -1;
  1006.  
  1007.     /*
  1008.      * Set the time stamps.  This assumes that universal time, not local
  1009.      * time, is used for time stamps.
  1010.      */
  1011.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1012.     fileDescPtr->createTime = time.seconds;
  1013.     fileDescPtr->accessTime = 0;
  1014.     fileDescPtr->descModifyTime = time.seconds;
  1015.     fileDescPtr->dataModifyTime = time.seconds;
  1016.  
  1017.  
  1018.     for (index = 0; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  1019.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  1020.     }
  1021.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  1022.     blockNum = 56 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  1023.     fileDescPtr->indirect[1] = blockNum;
  1024.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  1025.     fileDescPtr->numKbytes = 1;
  1026.     fileDescPtr->version = 1;
  1027. }
  1028.  
  1029. /*
  1030.  *----------------------------------------------------------------------
  1031.  *
  1032.  * SetDirFD --
  1033.  *
  1034.  *    File 17    
  1035.  *    Set up a file descriptor for an empty directory
  1036.  *
  1037.  * Results:
  1038.  *    Fill in the file descriptor.
  1039.  *
  1040.  * Side effects:
  1041.  *    None.
  1042.  *
  1043.  *----------------------------------------------------------------------
  1044.  */
  1045. void
  1046. SetDirFD(fileDescPtr)
  1047.     register FsFileDescriptor *fileDescPtr;
  1048. {
  1049.     Time time;
  1050.     int index;
  1051.  
  1052.     fileDescPtr->flags =   FS_FD_ALLOC;
  1053.     fileDescPtr->fileType =  FS_DIRECTORY;
  1054.     fileDescPtr->permissions = 0755;
  1055.     fileDescPtr->uid = 0;
  1056.     fileDescPtr->gid = 0;
  1057.     fileDescPtr->lastByte = FS_DIR_BLOCK_SIZE-1;
  1058.     fileDescPtr->firstByte = -1;
  1059.     fileDescPtr->numLinks = 0;
  1060.     /*
  1061.      * Can't know device information because that depends on
  1062.      * the way the system is configured.
  1063.      */
  1064.     fileDescPtr->devServerID = -1;
  1065.     fileDescPtr->devType = -1;
  1066.     fileDescPtr->devUnit = -1;
  1067.  
  1068.     /*
  1069.      * Set the time stamps.  This assumes that universal time, not local
  1070.      * time, is used for time stamps.
  1071.      */
  1072.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1073.     fileDescPtr->createTime = time.seconds;
  1074.     fileDescPtr->accessTime = 0;
  1075.     fileDescPtr->descModifyTime = time.seconds;
  1076.     fileDescPtr->dataModifyTime = time.seconds;
  1077.  
  1078.     /*
  1079.      * Place the data in the first filesystem block.
  1080.      */
  1081.     fileDescPtr->direct[0] = 64;
  1082.     for (index = 1; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  1083.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  1084.     }
  1085.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  1086.     fileDescPtr->indirect[index] = FS_NIL_INDEX;
  1087.     }
  1088.     fileDescPtr->numKbytes = 1;
  1089.     fileDescPtr->version = 1;
  1090. }
  1091.  
  1092. /*
  1093.  *----------------------------------------------------------------------
  1094.  *
  1095.  * SetOutputFD --
  1096.  *
  1097.  *     File 18
  1098.  *
  1099.  * Results:
  1100.  *    None.
  1101.  *
  1102.  * Side effects:
  1103.  *    None.
  1104.  *
  1105.  *----------------------------------------------------------------------
  1106.  */
  1107. void
  1108. SetOutputFD(fileDescPtr)
  1109.     register FsFileDescriptor *fileDescPtr;
  1110. {
  1111.     Time time;
  1112.     int index;
  1113.     int blockNum;
  1114.  
  1115.  
  1116.     fileDescPtr->flags = FS_FD_ALLOC;
  1117.     fileDescPtr->fileType = FS_FILE;
  1118.     fileDescPtr->permissions = 0755;
  1119.     fileDescPtr->uid = 0;
  1120.     fileDescPtr->gid = 0;
  1121.     fileDescPtr->lastByte = 2 * FS_BLOCK_SIZE - 1;
  1122.     fileDescPtr->firstByte = -1;
  1123.     fileDescPtr->numLinks = 1;
  1124.     /*
  1125.      * Can't know device information because that depends on
  1126.      * the way the system is configured.
  1127.      */
  1128.     fileDescPtr->devServerID = -1;
  1129.     fileDescPtr->devType = -1;
  1130.     fileDescPtr->devUnit = -1;
  1131.  
  1132.     /*
  1133.      * Set the time stamps.  This assumes that universal time, not local
  1134.      * time, is used for time stamps.
  1135.      */
  1136.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1137.     fileDescPtr->createTime = time.seconds;
  1138.     fileDescPtr->accessTime = 0;
  1139.     fileDescPtr->descModifyTime = time.seconds;
  1140.     fileDescPtr->dataModifyTime = time.seconds;
  1141.  
  1142.     fileDescPtr->direct[0] = 68;
  1143.     fileDescPtr->direct[1] = 72;
  1144.  
  1145.     for (index = 2; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  1146.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  1147.     }
  1148.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  1149.     fileDescPtr->indirect[1] = FS_NIL_INDEX;
  1150.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  1151.     fileDescPtr->numKbytes = 8;
  1152.     fileDescPtr->version = 1;
  1153. }
  1154.  
  1155. /*
  1156.  *----------------------------------------------------------------------
  1157.  *
  1158.  * SetBadDotDotFD --
  1159.  *
  1160.  *     File 21
  1161.  *    The ".." entry points to an unallocated file descriptor (22).
  1162.  *
  1163.  * Results:
  1164.  *    None.
  1165.  *
  1166.  * Side effects:
  1167.  *    None.
  1168.  *
  1169.  *----------------------------------------------------------------------
  1170.  */
  1171. void
  1172. SetOutputFD(fileDescPtr)
  1173.     register FsFileDescriptor *fileDescPtr;
  1174. {
  1175.     Time time;
  1176.     int index;
  1177.     int blockNum;
  1178.  
  1179.  
  1180.     fileDescPtr->flags = FS_FD_ALLOC;
  1181.     fileDescPtr->fileType = FS_DIRECTORY;
  1182.     fileDescPtr->permissions = 0755;
  1183.     fileDescPtr->uid = 0;
  1184.     fileDescPtr->gid = 0;
  1185.     fileDescPtr->lastByte = FS_DIR_BLOCK_SIZE-1;
  1186.     fileDescPtr->firstByte = -1;
  1187.     fileDescPtr->numLinks = 0;
  1188.     /*
  1189.      * Can't know device information because that depends on
  1190.      * the way the system is configured.
  1191.      */
  1192.     fileDescPtr->devServerID = -1;
  1193.     fileDescPtr->devType = -1;
  1194.     fileDescPtr->devUnit = -1;
  1195.  
  1196.     /*
  1197.      * Set the time stamps.  This assumes that universal time, not local
  1198.      * time, is used for time stamps.
  1199.      */
  1200.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1201.     fileDescPtr->createTime = time.seconds;
  1202.     fileDescPtr->accessTime = 0;
  1203.     fileDescPtr->descModifyTime = time.seconds;
  1204.     fileDescPtr->dataModifyTime = time.seconds;
  1205.  
  1206.     fileDescPtr->direct[0] = 76;
  1207.  
  1208.     for (index = 1; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  1209.     fileDescPtr->direct[index] = FS_NIL_INDEX;
  1210.     }
  1211.     fileDescPtr->indirect[0] = FS_NIL_INDEX;
  1212.     fileDescPtr->indirect[1] = FS_NIL_INDEX;
  1213.     fileDescPtr->indirect[2] = FS_NIL_INDEX;
  1214.     fileDescPtr->numKbytes = 1;
  1215.     fileDescPtr->version = 1;
  1216. }
  1217.  
  1218.  
  1219. @
  1220.